home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / psp_io.zip / DOSIO.ASM < prev    next >
Assembly Source File  |  1994-05-28  |  8KB  |  203 lines

  1. ;****************************************************************************
  2. ;                               I O D O S . A S M
  3. ;============================================================================
  4. ;       Input and output routines using DOS interrupts and functions.
  5. ;---------------------------------------------------------------------------
  6. ; Copyright (c) Simon Groes, 1994
  7. ;---------------------------------------------------------------------------
  8. ; Assemble with Borland Turbo Assembler v3.0
  9. ;****************************************************************************
  10.  
  11.         IDEAL
  12.         DOSSEG
  13.         MODEL   small
  14.         LOCALS
  15.  
  16. ;-----  Insert INCLUDE "filename" directives here
  17.         INCLUDE "macro.inc"
  18.         INCLUDE "common.inc"
  19.  
  20. ;-----  Insert EQU and = equates here
  21. BufSize         =       0FFh            ; Maximum string size (<=255).
  22.  
  23. STRUC   StrBuffer
  24.  maxLength      db      BufSize         ; Maximum buffer length.
  25.  strLength      db      0               ; Length of actual string in buffer.
  26.  theString      db      BufSize DUP (0) ; The string of chars.
  27. ENDS    StrBuffer
  28.  
  29.         DATASEG
  30.  
  31. dosBuffer       StrBuffer       <>      ; For dosGetStr
  32.  
  33. ;-----  Specify any EXTRN variables here
  34.  
  35.         CODESEG
  36.  
  37.         EXTRN   strLength:proc, strCopy:proc
  38.  
  39. ;-----  Declare PUBLIC procedures here
  40.         PUBLIC  dosPutString, dosKeyPress, dosGetRawChar, dosPutChar
  41.         PUBLIC  dosGetString, dosNewLine, dosGetEchoChar
  42.  
  43. ;===============================================================
  44. ; Procedure:    =*=dosPutString=*=
  45. ;---------------------------------------------------------------
  46. ; Usage:        Public - May be used in this & other asm files.
  47. ; Task:         Write string to screen using DOS function 40h of int 21h.
  48. ; Input:        di = offset address of string.
  49. ; Output:       String written to screen (handle 1: std output device).
  50. ; Registers:    none
  51. ;===============================================================
  52. PROC    dosPutString
  53.  
  54.         SaveRegs        <ax, bx, cx, dx>
  55.  
  56.         call    strLength            ; Length of string in cx.
  57.         mov     dx, di                  ; Offset should be in dx.
  58.         mov     bx, HANDLE_1            ; Handle #1 (screen).
  59.         Function        40h             ; Function 40 in ah.
  60.         DOS_21H                         ; Call int 21h.
  61.  
  62.         RestoreRegs     <dx, cx, bx, ax>
  63.         ret
  64. ENDP    dosPutString
  65.  
  66. ;===============================================================
  67. ; Procedure:    =*=dosKeyPress=*=
  68. ;---------------------------------------------------------------
  69. ; Task:         Wait for key press.
  70. ; Input:        none
  71. ; Output:       none
  72. ; Registers:    none
  73. ; Note:         Unfiltered input means special input such as CTRL+C
  74. ;               are not interpreted to instructions.
  75. ;               Function 07h reads char from keyboard input buffer.
  76. ;               If empty, waits for keypress. Char read is in al.
  77. ;===============================================================
  78. PROC    dosKeyPress
  79.  
  80.         SaveRegs        <ax>
  81.         Function        07h     ; Read unfiltered char. Char in al.
  82.         DOS_21H                 ; Call dos int 21h.
  83.         RestoreRegs     <ax>
  84.         ret
  85. ENDP    dosKeyPress
  86.  
  87. ;===============================================================
  88. ; Procedure:    =*=dosGetRawChar=*=
  89. ;---------------------------------------------------------------
  90. ; Task:         Get unfiltered character from keyboard,
  91. ;               if none available, wait for keypress.
  92. ; Input:        none
  93. ; Output:       al = ASCII value of character.
  94. ; Registers:    ax changed.
  95. ; Note:         Unfiltered input means special input such as CTRL+C
  96. ;               are not interpreted to instructions.
  97. ;               Function 07h reads char from keyboard input buffer.
  98. ;               If empty, waits for keypress. Char read is in al.
  99. ;===============================================================
  100. PROC    dosGetRawChar
  101.  
  102.         Function        07h     ; Read unfiltered char. Char in al.
  103.         DOS_21H                 ; Call dos interrupt 21h.
  104.         xor     ah, ah          ; Clear ah register.
  105.         ret                     ; Return to caller.
  106. ENDP    dosGetRawChar
  107.  
  108. ;===============================================================
  109. ; Procedure:    =*=dosPutChar=*=
  110. ;---------------------------------------------------------------
  111. ; Task:         Display filtered character on screen.
  112. ; Input:        al = character to be displayed.
  113. ; Output:       none
  114. ; Registers:    ax changed.
  115. ; Note:         Filtered means special characters such as
  116. ;               CTRL+C, CTRL+S, Return etc are treated as
  117. ;               system control keys an not mere ASCII values.
  118. ;===============================================================
  119. PROC    dosPutChar
  120.  
  121.         SaveRegs <dx>
  122.         mov     dl, al          ; Dos function requires char in dl.
  123.         Function 02h            ; Filtered character output.
  124.         DOS_21H                 ; Call dos interrupt 21h.
  125.         RestoreRegs <dx>
  126.         ret                     ; Return to caller.
  127. ENDP    dosPutChar
  128.  
  129. ;===============================================================
  130. ; Procedure:    =*dosGetEchoChar=*=
  131. ;---------------------------------------------------------------
  132. ; Task:         Get char input from keyboard buffer and echo to screen.
  133. ; Input:        none
  134. ; Output:       al = character read.
  135. ; Registers:    ax changed.
  136. ; Note:         Recognises ASCII control codes.
  137. ;               If no char in buffer, function waits until one
  138. ;               is available.
  139. ;===============================================================
  140. PROC    dosGetEchoChar
  141.         Function 01h            ; Character input with echo.
  142.         DOS_21H                 ; Call dos interrupt 21h.
  143.         xor     ah, ah          ; Clear ah.
  144.         ret
  145. ENDP    dosGetEchoChar
  146.  
  147.  
  148.  
  149. ;===============================================================
  150. ; Procedure:    =*=dosGetString=*=
  151. ;---------------------------------------------------------------
  152. ; Task:         Get string (buffered input) from keyboard, and
  153. ;               store in buffer.
  154. ; Input:        di = Address of buffer to hold string.
  155. ;               cl = Maximum string length (excluding NULL).
  156. ; Output:       String copied from standard input (keyboard) to buffer.
  157. ; Registers:    none
  158. ; Note:         Character input ends when user presses <enter>.
  159. ;               Max # of chars includes <enter>.
  160. ;===============================================================
  161. PROC    dosGetString
  162.  
  163.         or      cl, cl          ; Value in cl ?
  164.         jz      @@Return        ; No:  End routine.
  165.  
  166.         SaveRegs <ax,bx,dx,si>
  167.  
  168.         mov     [dosBuffer.maxLength], cl       ; Max length in 1st byte.
  169.         mov     dx, OFFSET dosBuffer.maxLength  ; dx -> dosBuffer.
  170.         Function 0Ah                            ; Buffered-Input.
  171.         DOS_21H                                 ; Call dos int 21h.
  172.         mov     si, OFFSET dosBuffer.theString  ; si -> string.
  173.         xor     bh,bh                           ; Clear bh.
  174.         mov     bl, [dosBuffer.strLength]       ; bl = string length - <rtn>.
  175.         mov     [BYTE bx+si], NULL              ; Replace <enter> with NULL.
  176.         call    strCopy                         ; Copy string to [di].
  177. @@Return:
  178.         RestoreRegs <si,dx,bx,ax>
  179.         ret                                     ; Return to caller.
  180. ENDP    dosGetString
  181.  
  182. ;===============================================================
  183. ; Procedure:    =*=dosNewLine=*=
  184. ;---------------------------------------------------------------
  185. ; Task:         Move cursor to the beginning of the next line.
  186. ; Input:        none
  187. ; Output:       none
  188. ; Registers:    none
  189. ;===============================================================
  190. PROC    dosNewLine
  191.  
  192.         SaveRegs<ax,dx>
  193.         Function 02h
  194.         mov     dl, LF          ; Move to next line.
  195.         DOS_21H
  196.         mov     dl, CR          ; Move to beginning of line.
  197.         DOS_21H
  198.         RestoreRegs<dx,ax>
  199.         ret                     ; Return to caller.
  200. ENDP    dosNewLine
  201.  
  202.         END             ; End of routines.
  203.